﻿@model Lari.Services.ViewModel.TitleListModel
@using Lari.Configuration
@{
    var grid = new WebGrid(Model.List, rowsPerPage: ApplicationConfig.RowPerPage,
    canPage: true, canSort: true, defaultSort: "Name");
    grid.Pager(WebGridPagerModes.Numeric);
   
}
<div id="pagetitle">
    <h1>@ScreenName.Masters.Titles</h1>
</div>
<div class="spacer">
</div>
<div id="pagecontent">
    <div class="spacer">
    </div>
    <div id="grid" style="width: 40%; float: left;">
        @grid.GetHtml(
            tableStyle: "webgrid",
            headerStyle: "webgrid-header",
            footerStyle: "webgrid-footer",
            alternatingRowStyle: "webgrid-alternating-row",
            selectedRowStyle: "webgrid-selected-row",
            rowStyle: "webgrid-row-style",
            columns: grid.Columns(grid.Column("Name", "Titles"),
                                  grid.Column(format: @<text><a href="#" onclick="Edit('@item.id','@item.Name',this)">@GuiActionName.Update</a></text>)

                                                   )


                                              )
    </div>
    <div style="width: 55%; float: right;">
        <div id="edit" style="border: 0px solid red">
             @using (Html.BeginForm(ActionConst.Masters.Common.TitleModify, ControllerConst.Masters.CoreMaster))
             {
                @Html.AntiForgeryToken("modify title")
                <div>
                    <label class="required">Title</label>&nbsp;&nbsp;<strong style="font-size:10px;font-weight: bold"> (Edit)</strong>
                    @Html.HiddenFor(m => m.Edit.ID, new { id = "editId" })
                </div>
                <div>
                    @Html.TextBoxFor(m => m.Edit.Name, new { id = "editName" })
                    @Html.ValidationMessageFor(m => m.Edit.Name)
                </div>
                <div class="doubleSpacer">
                </div>
                <div>
                    <input type="submit" value="@GuiActionName.Modify" id="btnModify" />
                </div>
             }
        </div>
        <div id="insert" style="border: 0px solid red">
            @using (Html.BeginForm(ActionConst.Masters.Common.TitleCreate, ControllerConst.Masters.CoreMaster))
            {
                @Html.AntiForgeryToken("New title")
                <div>
                    <label class="required">Title</label>&nbsp;&nbsp;<strong style="font-size:10px;font-weight: bold"> (New)</strong>
                </div>
                <div>
                    @Html.TextBoxFor(m => m.Insert.Name, new { id = "insertName" })
                    @Html.ValidationMessageFor(m => m.Insert.Name)
                </div>
                <div class="doubleSpacer">
                </div>
                <div>
                    <input type="submit" value="@GuiActionName.Save" id="btnSubmit" />
                </div>
            }
        </div>
    </div>
    <div class="clear">
    </div>
    <div class="doubleSpacer">
    </div>
    <div>
        <a href="#" id="hrefInsert">@ScreenName.Masters.TitleCreate</a>
    </div>
    <div class="spacer">
    </div>
</div>
<script type="text/javascript">
    
    var previousRow;
    var previousClass;
    
    function Edit(id, name,obj) 
    {
        $("#edit").show();
        $("#insert").hide();
        $("#editId").val(id);
        $("#editName").val(name);
        if(previousRow!=null && previousClass!=null) 
        {
            previousRow.setAttribute('class', previousClass);
        }

        previousRow = obj.parentNode.parentNode;
        //alert(previousRow);
        previousClass = obj.parentNode.parentNode.className;
         //alert(previousClass);
        
        //previousRow
        obj.parentNode.parentNode.setAttribute('class', 'webgrid-selected-row '+previousClass);

        return false;
        
    }
   
    $(document).ready(function () {

        @if (Model.Edit == null)
        {
            <text> $("#edit").hide();</text>

        }
        @if (Model.Insert == null)
        {
            <text> $("#insert").hide();</text>

        }
        
        $("#btnSubmit").button();
        $("#btnModify").button();
        
        $("#hrefInsert").click(function() {
            $("#edit").hide();
            $("#insert").show();
        });
    });
</script>
